﻿<%@ Page Language="C#" MasterPageFile="~/Shared/DialogPage.Master" AutoEventWireup="true" CodeBehind="SelectDeptMultiple.aspx.cs" Inherits="Runda.CMS.Portal.Workspace.winSelectDeptMultiple" StylesheetTheme="GlobleTheme" %>
<%@ Register Assembly="RadTreeView.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="../Content/global.css" rel="stylesheet" type="text/css" />
    <script src="../Content/global.js" type="text/javascript"></script>
    <link href="../Content/Menu/Menu.css" rel="stylesheet" type="text/css" />
       <link href="../Content/Tab/tabs.css" rel="stylesheet" type="text/css" /> 
       
<script type="text/javascript">
    function GetRadWindow() {
        var oWindow = null;
        if (window.radWindow) oWindow = window.radWindow;
        else if (window.frameElement.radWindow)
            oWindow = window.frameElement.radWindow;
        return oWindow;
    }

    function CloseWindow() {
        var oWindow = GetRadWindow();
        oWindow.Argument = '';
        oWindow.Close();
    }

    function SaveAndCloseWindow() {
        var oWindow = GetRadWindow();
        oWindow.Argument = 'changed';
        oWindow.Close();
    }

    function SaveAndCloseWindow1(arg) {
        var oWindow = GetRadWindow();
        oWindow.Argument = arg;
        oWindow.Close();
    }
   

    function GetCheckedNodes()
    {
       var tree = <%= RadTreeView1.ClientID%>;
       var text = "";
       var value = "";
       var hasCheckedNodes = false;
                   
        for (var i=0; i<tree.AllNodes.length; i++)
        {                        
            if (tree.AllNodes[i].Checked == true)
            {
                text = text + tree.AllNodes[i].Text + "; ";
                value = value + tree.AllNodes[i].Value + "; ";
                hasCheckedNodes = true;
            }                    
        }
        
        if (hasCheckedNodes)
        {
            var arg = new Array();
            arg[0] =value;
            arg[1] = text;           
            SaveAndCloseWindow1(arg);
        }
        else
        {
            alert("请选择部门!");
        }
      }
      
    function AfterCheck(node)
    {
        if (!node.Checked && node.Parent != null)
            {
                node.Parent.UnCheck();    
            }

        var siblingCollection = (node.Parent != null) ? node.Parent.Nodes : node.TreeView.Nodes;

        var allChecked = true;
        for (var i=0; i<siblingCollection.length; i++)
            {
                if (!siblingCollection[i].Checked)
                {
                    allChecked = false;
                    break;
                }
            }
        if (allChecked && node.Parent != null)
            {
                node.Parent.Check();
            }
 
        UpdateAllChildren(node.Nodes, node.Checked);
    }

    function UpdateAllChildren(nodes, checked)
    {
        var i;
        for (i=0; i<nodes.length; i++)
        {
            if (checked)         
                nodes[i].Check();         
            else        
                nodes[i].UnCheck(); 

            if (nodes[i].Nodes.length > 0)        
                UpdateAllChildren(nodes[i].Nodes, checked);        
        }
    }

    </script>

 
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 
    <table class="mnubar" cellspacing="0" cellpadding="0">
        <tbody>
            <tr>
                <td style="padding-left: 5px" nowrap>
                    <b>部门</b>
                </td>
                <td style="padding-left: 5px">
                    <img src="../Content/Grid/separator.gif">
                </td>
                <td class="icMenu" nowrap> 
                </td>
                <td class="icMenu mnuRight" nowrap>
                      
                </td>
            </tr>
        </tbody>
    </table> 
    <div style="display: inline" id="appForm_tab0" class="tab">
        <div style="padding:0;margin:0;overflow: auto;float:left;width: 100%; height:370px"> 
            <rad:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="True" AfterClientCheck="AfterCheck"></rad:RadTreeView>
        </div>
        <div>
            <asp:Button ID="btnSave" runat="server" Text="保存" CssClass="button" OnClientClick="GetCheckedNodes();return false;"/>
                &nbsp;&nbsp;
                <asp:Button ID="btnCancel" runat="server" Text="取消" CssClass="button" OnClientClick="CloseWindow();"/>
        </div>
    </div>
 
</asp:Content>
